function createWallSegments(y){
    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/BorderWall.qml"),
                         {"x": 0,
                             "y": y
                         });

    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/BorderWallRight.qml"),
                         {"x": level.width - 24,
                             "y": y
                         });
}

function createFullBlock(y){
    var x = level.gridSize/2;
    console.debug("in createFullBlock", x, y);

    while(x < level.width){
        console.debug("fullblock: creating a new Platform at position", x, y);
        entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Platform.qml"),
                             {"x": x,
                                 "y": y
                             });
        x += level.gridSize;
    }
}

function createPlatforms(){
    // at least one platform per row
    var randomPosition = ((Math.random()*(3)+1).toFixed()*1);
//    var randomPosition = Math.random()*(platformColumns.toFixed()-4)+1;
    console.debug("pos:", randomPosition);

    console.debug("first platform created!");
    LevelLogic.createPlatformAtPosition(randomPosition);
    // 50 % chance for a second one
    if(Math.random() <= probabilityPlatform2){
        console.debug("second platform created!")
        LevelLogic.createPlatformAtPosition(randomPosition+1);
    }
      // 30 % for a third one
    if(Math.random() <= probabilityPlatform3 && randomPosition < 4){
         console.debug("third platform created!")
        LevelLogic.createPlatformAtPosition(randomPosition+2);
    }
    if(Math.random() <= probabilityCoin){
        LevelLogic.createCoinAtPosition(randomPosition);
    }
    if(Math.random() <= probabilityBooster){
        LevelLogic.createBoosterAtPosition(randomPosition);
    }
    if(Math.random() <= probabilitySlowDowner){
        LevelLogic.createSlowDownerAtPosition(randomPosition);
    }
}

function createPlatformAtPosition(platformPosition){

    var newRoostCenterPos = Qt.point(platformPosition*gridSize + gridSize/2, -y);
    //var newRoostCenterPos = Qt.point(platformPosition*gridSize + gridSize/2, -y);

    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Platform.qml"),
                         {"x": newRoostCenterPos.x,
                             "y": newRoostCenterPos.y
                         });
}

function createCoinAtPosition(coinPosition){
    var newCoinCenterPos = Qt.point(coinPosition * gridSize + gridSize / 2, -y - gridSize - 10);

    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Coin.qml"),
                         {"x": newCoinCenterPos.x,
                             "y": newCoinCenterPos.y
                         });
}

function createBoosterAtPosition(boosterPosition){
    var newBoosterCenterPos = Qt.point(boosterPosition * gridSize + gridSize / 2, -y - gridSize - 10);

    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/Booster.qml"),
                         {"x": newBoosterCenterPos.x,
                             "y": newBoosterCenterPos.y
                         });
}

function createSlowDownerAtPosition(slowDownerPosition){
    var newSlowDownerPosition = Qt.point(slowDownerPosition * gridSize + gridSize / 2, -y - gridSize - 10);

    entityManager.createEntityFromUrlWithProperties(Qt.resolvedUrl("../entities/SlowDowner.qml"),
                         {"x": newSlowDownerPosition.x,
                             "y": newSlowDownerPosition.y
                         });
}
